package com.i2works.smartluolong.manageapi.config;

import com.i2works.smartluolong.utils.config.RedisConfigurationUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.RedisSerializer;

/**
 * redis配置
 *
 * @author Liu Yutao <koal@vip.qq.com>
 * @date 2018/1/30 13:27
 */
@Configuration
@EnableCaching
public class RedisConfiguration {

    /**
     * 注入 RedisConnectionFactory
     */
    @Autowired
    RedisConnectionFactory redisConnectionFactory;

    /**
     * fastjson实例化
     */
    @Bean
    public RedisSerializer fastJson2JsonRedisSerializer() {
        return RedisConfigurationUtils.fastJson2JsonRedisSerializer();
    }

    /**
     * 实例化 RedisTemplate 对象
     */
    @Bean
    public RedisTemplate<String, String> redisTemplate(RedisConnectionFactory factory, RedisSerializer fastJson2JsonRedisSerializer) {
        return RedisConfigurationUtils.redisTemplate(factory, fastJson2JsonRedisSerializer);
    }
}
